import request from '~/utils/http'
import type { ApiResponse, SaveVisitorParams, ExamineParams, GetInfoParams, VisitorInfo } from '~/types/api'

export const getInfoByCodeApi = (data: GetInfoParams, isLoading?: boolean): Promise<ApiResponse<VisitorInfo>> => {
  const config = useRuntimeConfig()
  return request(`${config.public.apiBase}/ezsafe-server/enterpriseOutWork/lastInfo/${data.WXID}?QYBH=${data.QYBH}`, isLoading, {
    method: 'GET'
  })
}

export const getDetailsApi = (data: string, isLoading?: boolean): Promise<ApiResponse<VisitorInfo>> => {
  const config = useRuntimeConfig()
  return request(`${config.public.apiBase}/ezsafe-server/enterpriseOutWork/detail/${data}`, isLoading, {
    method: 'GET'
  })
}

export const getListApi = (data: any, isLoading?: boolean): Promise<ApiResponse<VisitorInfo[]>> => {
  const config = useRuntimeConfig()
  return request(`${config.public.apiBase}/ezsafe-server/enterpriseOutWork/appletPage`, isLoading, {
    method: 'post',
    data: data
  })
}

export const getFDListApi = (data: any, isLoading?: boolean): Promise<ApiResponse<any>> => {
  const config = useRuntimeConfig()
  return request(`${config.public.apiBase}/ezsafe-server/enterpriseOutWork/fdAppPage`, isLoading, {
    method: 'post',
    data: data
  })
}

export const examineApi = (data: ExamineParams, isLoading?: boolean): Promise<ApiResponse> => {
  const config = useRuntimeConfig()
  return request(`${config.public.apiBase}/ezsafe-server/enterpriseOutWork/examine`, isLoading, {
    method: 'post',
    data: data
  })
}

export const endWorkApi = (data: string, isLoading?: boolean): Promise<ApiResponse> => {
  const config = useRuntimeConfig()
  return request(`${config.public.apiBase}/ezsafe-server/enterpriseOutWork/endWork/${data}`, isLoading, {
    method: 'put'
  })
}

export const saveApi = (data: SaveVisitorParams, isLoading: boolean = false): Promise<ApiResponse> => {
  const config = useRuntimeConfig()
  return request(`${config.public.apiBase}/ezsafe-server/enterpriseOutWork/save`, isLoading, {
    method: 'POST',
    data: data
  })
}

export const getTokenApi = (isLoading?: boolean): Promise<ApiResponse> => {
  const config = useRuntimeConfig()
  return request(`${config.public.apiBase}/ezsafe-server/landlordLogin/logon`, isLoading, {
    method: 'get'
  })
}

export const getQrCodeImgApi = (data: any, isLoading?: boolean): Promise<ApiResponse> => {
  const config = useRuntimeConfig()
  return request(`${config.public.apiBase}/ezsafe-server/qrCode/enterpriseQrCode`, isLoading, {
    method: 'post',
    data: data
  })
}

export const getZKListApi = (data: any, isLoading?: boolean): Promise<ApiResponse> => {
  const config = useRuntimeConfig()
  return request(`${config.public.apiBase}/ezsafe-server/projectLease/rentingZk`, isLoading, {
    method: 'post',
    data: data
  })
}

export const getZKDetailApi = (data: any, isLoading?: boolean): Promise<ApiResponse<VisitorInfo>> => {
  const config = useRuntimeConfig()
  return request(`${config.public.apiBase}/ezsafe-server/enterpriseOutWork/lastOne`, isLoading, {
    method: 'post',
    data: data
  })
}
